<?php
$query_profile = "SELECT profile, extprofile FROM character_ WHERE id=" . $_GET["id"];
$result_profile = mysql_query($query_profile,$db);
$db_row_profile = mysql_fetch_array($result_profile);

$profileResult = $db_row_profile["profile"];
$extprofileResult = $db_row_profile["extprofile"];

// Convert profile into array Profile[]

$Profile["checksum"] = asc2bin(substr($profileResult,0,4));
$Profile["checksum_PHP-crc32"] = str_pad(decbin(crc32(substr($profileResult,4))),32,"0",STR_PAD_LEFT);
$Profile["checksum_PHP-funct"] = str_pad(decbin(SetEQChecksum(substr($profileResult,4))),32,"0",STR_PAD_LEFT);
$Profile["name"] = rtrim(substr($profileResult,4,64));
$Profile["last_name"] = rtrim(substr($profileResult,68,32));
$Profile["gender"] = asc2uint(substr($profileResult,100,4));
$Profile["race"] = asc2uint(substr($profileResult,104,4));
$Profile["class"] = asc2uint(substr($profileResult,108,4));
$Profile["level"] = asc2uint(substr($profileResult,116,4));

// BindStruct[5]
	for ($x = 0; $x <= 4; $x++) {
		// zoneID is the same as zoneidnumber from the table "zone" in the database
		$Profile["binds"][$x+1]["zoneID"] = asc2uint(substr($profileResult,$x*20+120,4));
		$Profile["binds"][$x+1]["x"] = asc2float(substr($profileResult,$x*20+124,4));
		$Profile["binds"][$x+1]["y"] = asc2float(substr($profileResult,$x*20+128,4));
		$Profile["binds"][$x+1]["z"] = asc2float(substr($profileResult,$x*20+132,4));
		$Profile["binds"][$x+1]["heading"] = asc2float(substr($profileResult,$x*20+136,4));
	};

$Profile["diety"] = asc2uint(substr($profileResult,220,4));
$Profile["guild_id"] = asc2uint(substr($profileResult,224,4));
$Profile["birthday"] = asc2uint(substr($profileResult,228,4));
$Profile["lastlogin"] = asc2uint(substr($profileResult,232,4));
$Profile["timePlayedMin"] = asc2uint(substr($profileResult,236,4));
$Profile["pvp"] = asc2uint(substr($profileResult,240,1));
$Profile["level2"] = asc2uint(substr($profileResult,241,1));
$Profile["anon"] = asc2uint(substr($profileResult,242,1));
$Profile["gm"] = asc2uint(substr($profileResult,243,1));
$Profile["guildrank"] = asc2uint(substr($profileResult,244,1));

// unknown0245[9]
/*	for ($x = 0; $x <= 8; $x++) {
		$Profile["unknown0245"][$x+1] = asc2uint(substr($profileResult,$x+245,1));
	};
*/

$Profile["intoxication"] = asc2uint(substr($profileResult,252,4));

// unknown0392[4]
/*	for ($x = 0; $x <= 3; $x++) {
		$Profile["unknown0392"][$x+1] = asc2uint(substr($profileResult,$x+292,1));
	};
*/

$Profile["haircolor"] = asc2uint(substr($profileResult,296,1));
$Profile["beardcolor"] = asc2uint(substr($profileResult,297,1));
$Profile["eyecolor1"] = asc2uint(substr($profileResult,298,1));
$Profile["eyecolor2"] = asc2uint(substr($profileResult,299,1));
$Profile["hairstyle"] = asc2uint(substr($profileResult,300,1));
$Profile["beard"] = asc2uint(substr($profileResult,301,1));
$Profile["ability_time_seconds"] = asc2uint(substr($profileResult,302,1));
$Profile["ability_number"] = asc2uint(substr($profileResult,303,1));
$Profile["ability_time_minutes"] = asc2uint(substr($profileResult,304,1));
$Profile["ability_time_hours"] = asc2uint(substr($profileResult,305,1));

// unknown0306[6]
/*	for ($x = 0; $x <= 5; $x++) {
		$Profile["unknown0306"][$x+1] = asc2uint(substr($profileResult,$x+306,1));
	};
*/

// item_material[9]
	for ($x = 0; $x <= 8; $x++) {
		$Profile["item_material"][$x+1] = asc2uint(substr($profileResult,$x*4+312,4));
	};

// unknown0256[44]
/*	for ($x = 0; $x <= 43; $x++) {
		$Profile["unknown0256"][$x+1] = asc2uint(substr($profileResult,$x+348,1));
	};
*/

// Color_Struct[9]
	for ($x = 0; $x <= 8; $x++) {
		$Profile["item_tint"][$x+1]["blue"] = asc2uint(substr($profileResult,$x*4+392,1));
		$Profile["item_tint"][$x+1]["green"] = asc2uint(substr($profileResult,$x*4+393,1));
		$Profile["item_tint"][$x+1]["red"] = asc2uint(substr($profileResult,$x*4+394,1));
		$Profile["item_tint"][$x+1]["use_tint"] = asc2uint(substr($profileResult,$x*4+395,1));
	};

// AA_Array[240]
	for ($x = 0; $x <= 239; $x++) {
		$aa = asc2uint(substr($profileResult,$x*8+428,4));
		$value = asc2uint(substr($profileResult,$x*8+432,4));
		if ($aa != 0) {
			$Profile["aa_array"][($aa-($value-1))] = $value;
		};
		unset($aa);		// Probably not very efficient...
		unset($value);	// Same...
	};
	unset($aa);
	unset($value);

// $Profile["unknown2348"] = asc2float(substr($profileResult,2348,4));
$Profile["servername"] = rtrim(substr($profileResult,2352,32));
$Profile["title"] = rtrim(substr($profileResult,2384,32));
$Profile["suffix"] = rtrim(substr($profileResult,2416,32));
$Profile["guildid2"] = asc2uint(substr($profileResult,2448,4));
$Profile["exp"] = asc2uint(substr($profileResult,2452,4));
// $Profile["unknown1496"] = asc2uint(substr($profileResult,2456,4));
$Profile["points"] = asc2uint(substr($profileResult,2460,4));
$Profile["mana"] = asc2uint(substr($profileResult,2464,4));
$Profile["cur_hp"] = asc2uint(substr($profileResult,2468,4));
// $Profile["unknown1512"] = asc2uint(substr($profileResult,2472,4));
$Profile["STR"] = asc2uint(substr($profileResult,2476,4));
$Profile["STA"] = asc2uint(substr($profileResult,2480,4));
$Profile["CHA"] = asc2uint(substr($profileResult,2484,4));
$Profile["DEX"] = asc2uint(substr($profileResult,2488,4));
$Profile["INT"] = asc2uint(substr($profileResult,2492,4));
$Profile["AGI"] = asc2uint(substr($profileResult,2496,4));
$Profile["WIS"] = asc2uint(substr($profileResult,2500,4));
$Profile["face"] = asc2uint(substr($profileResult,2504,1));

// unknown1545[47]
/*	for ($x = 0; $x <= 46; $x++) {
		$Profile["unknown1545"][$x+1] = asc2uint(substr($profileResult,$x+2505,1));
	};
*/

// languages[28]
	for ($x = 0; $x <= 27; $x++) {
		$Profile["languages"][$x+1] = asc2uint(substr($profileResult,$x+2552,1));
	};

// unknown1620[4]
/*	for ($x = 0; $x <= 3; $x++) {
		$Profile["unknown1620"][$x+1] = asc2uint(substr($profileResult,$x+2580,1));
	};
*/

// spell_book[400]
	for ($x = 0; $x <= 399; $x++) {
		$Profile["spell_book"][$x+1] = asc2uint(substr($profileResult,$x*4+2584,4));
	};

// unknown3224[448]
/*	for ($x = 0; $x <= 447; $x++) {
		$Profile["unknown3224"][$x+1] = asc2uint(substr($profileResult,$x+4184,1));
	};
*/

// mem_spells[9]
	for ($x = 0; $x <= 8; $x++) {
		$Profile["mem_spells"][$x+1] = asc2uint(substr($profileResult,$x*4+4632,4));
	};

// $Profile["unknown3704"] = asc2uint(substr($profileResult,4668,32));
$Profile["y"] = asc2float(substr($profileResult,4700,4));
$Profile["x"] = asc2float(substr($profileResult,4704,4));
$Profile["z"] = asc2float(substr($profileResult,4708,4));
$Profile["heading"] = asc2float(substr($profileResult,4712,4));
// $Profile["unknown3756"] = asc2uint(substr($profileResult,4716,4));
$Profile["platinum"] = asc2sint(substr($profileResult,4720,4));
$Profile["gold"] = asc2sint(substr($profileResult,4724,4));
$Profile["silver"] = asc2sint(substr($profileResult,4728,4));
$Profile["copper"] = asc2sint(substr($profileResult,4732,4));
$Profile["platinum_bank"] = asc2sint(substr($profileResult,4736,4));
$Profile["gold_bank"] = asc2sint(substr($profileResult,4740,4));
$Profile["silver_bank"] = asc2sint(substr($profileResult,4744,4));
$Profile["copper_bank"] = asc2sint(substr($profileResult,4748,4));
$Profile["platinum_cursor"] = asc2sint(substr($profileResult,4752,4));
$Profile["gold_cursor"] = asc2sint(substr($profileResult,4756,4));
$Profile["silver_cursor"] = asc2sint(substr($profileResult,4760,4));
$Profile["copper_cursor"] = asc2sint(substr($profileResult,4764,4));
$Profile["platinum_shared"] = asc2sint(substr($profileResult,4768,4));
// $Profile["unknown3812"] = asc2uint(substr($profileResult,4772,24));

// skills[75]
	for ($x = 0; $x <= 74; $x++) {
		$Profile["skills"][$x] = asc2uint(substr($profileResult,$x*4+4796,4));
	};

// $Profile["unknown5096"] = asc2uint(substr($profileResult,5096,284));
$Profile["pvp2"] = asc2uint(substr($profileResult,5380,4));
// $Profile["unknown4420"] = asc2uint(substr($profileResult,5384,4));
$Profile["pvptype"] = asc2uint(substr($profileResult,5388,4));
// $Profile["unknown4428"] = asc2uint(substr($profileResult,5392,4));
$Profile["ability_down"] = asc2uint(substr($profileResult,5396,4));
// $Profile["unknown4436"] = asc2uint(substr($profileResult,5400,8));
$Profile["autosplit"] = asc2uint(substr($profileResult,5408,4));
// $Profile["unknown4460"] = asc2uint(substr($profileResult,5412,8));
$Profile["zone_change_count"] = asc2uint(substr($profileResult,5420,4));
// $Profile["unknown4460"] = asc2uint(substr($profileResult,5424,28));
$Profile["expansions"] = asc2uint(substr($profileResult,5452,4));
$Profile["toxicity"] = asc2sint(substr($profileResult,5456,4));
// $Profile["unknown4496"] = substr($profileResult,5460,16);
$Profile["hunger_level"] = asc2sint(substr($profileResult,5476,4));
$Profile["thirst_level"] = asc2sint(substr($profileResult,5480,4));
$Profile["ability_up"] = asc2uint(substr($profileResult,5484,4));
// $Profile["unknown4524"] = substr($profileResult,5488,16);
$Profile["zone_id"] = asc2uint(substr($profileResult,5504,2));
$Profile["zoneInstance"] = asc2uint(substr($profileResult,5506,2));

// buffs[25]
	for ($x = 0; $x <= 24; $x++) {
		$Profile["buffs"][$x+1]["slotid"] = asc2uint(substr($profileResult,$x*20+5508,1));
		$Profile["buffs"][$x+1]["level"] = asc2uint(substr($profileResult,$x*20+5509,1));
		$Profile["buffs"][$x+1]["bard_modifier"] = asc2uint(substr($profileResult,$x*20+5510,1));
		$Profile["buffs"][$x+1]["effect"] = asc2uint(substr($profileResult,$x*20+5511,1));
		$Profile["buffs"][$x+1]["spellid"] = asc2uint(substr($profileResult,$x*20+5512,4));
		$Profile["buffs"][$x+1]["duration"] = asc2uint(substr($profileResult,$x*20+5516,4));
		$Profile["buffs"][$x+1]["dmg_shield_remaining"] = asc2uint(substr($profileResult,$x*20+5520,2));
		$Profile["buffs"][$x+1]["persistant_buff"] = asc2uint(substr($profileResult,$x*20+5522,1));
		$Profile["buffs"][$x+1]["reserved"] = asc2uint(substr($profileResult,$x*20+5523,1));
		$Profile["buffs"][$x+1]["player_id"] = asc2uint(substr($profileResult,$x*20+5524,4));
	};

// groupMembers[6]
	for ($x = 0; $x <= 5; $x++) {
		$Profile["groupMembers"][$x+1] = rtrim(substr($profileResult,$x*64+6008,64));
	};
// $Profile["unknown6392"] = substr($profileResult,6392,668);
$Profile["ldon_points_guk"] = asc2sint(substr($profileResult,7060,4));
$Profile["ldon_points_mir"] = asc2sint(substr($profileResult,7064,4));
$Profile["ldon_points_mmc"] = asc2sint(substr($profileResult,7068,4));
$Profile["ldon_points_ruj"] = asc2sint(substr($profileResult,7072,4));
$Profile["ldon_points_tak"] = asc2sint(substr($profileResult,7076,4));
$Profile["ldon_points_available"] = asc2sint(substr($profileResult,7080,4));
// $Profile["unknown5940"] = asc2uint(substr($profileResult,7084,112));
$Profile["tribute_time_remaining"] = asc2uint(substr($profileResult,7196,4));
// $Profile["unknown6048"] = asc2uint(substr($profileResult,7200,4));
$Profile["career_tribute_points"] = asc2uint(substr($profileResult,7204,4));
// $Profile["unknown6056"] = asc2uint(substr($profileResult,7208,4));
$Profile["tribute_points"] = asc2uint(substr($profileResult,7212,4));
// $Profile["unknown6064"] = asc2uint(substr($profileResult,7216,4));
$Profile["tribute_active"] = asc2uint(substr($profileResult,7220,4));

// tributes[5]
	for ($x = 0; $x <= 4; $x++) {
		$Profile["tributes"][$x+1]["tribute"] = asc2uint(substr($profileResult,$x*8+7224,4));
		$Profile["tributes"][$x+1]["tier"] = asc2uint(substr($profileResult,$x*8+7228,4));
	};

// disciplines[100]
	for ($x = 0; $x <= 99; $x++) {
		$Profile["disciplines"][$x+1] = asc2uint(substr($profileResult,$x*4+7264,4));
	};

// $Profile["unknown7464"] = substr($profileResult,7664,240);
$Profile["endurance"] = asc2uint(substr($profileResult,7904,2));
$Profile["group_leadership_exp"] = asc2uint(substr($profileResult,7908,4));
$Profile["raid_leadership_exp"] = asc2uint(substr($profileResult,7912,4));
$Profile["group_leadership_points"] = asc2uint(substr($profileResult,7916,4));
$Profile["raid_leadership_points"] = asc2uint(substr($profileResult,7920,4));

// leader_abilities[32]
	for ($x = 0; $x <= 31; $x++) {
		$Profile["leader_abilities"][$x+1]["ranks"] = asc2uint(substr($profileResult,$x*4+7924,4));
	};

// $Profile["unknown8052"] = asc2uint(substr($profileResult,8052,132));
$Profile["air_remaining"] = asc2uint(substr($profileResult,8184,4));
// $Profile["unknown8188"] = asc2uint(substr($profileResult,8188,4608));
$Profile["aapoints_spent"] = asc2uint(substr($profileResult,12796,4));
$Profile["expAA"] = asc2uint(substr($profileResult,12800,4));
$Profile["aapoints"] = asc2uint(substr($profileResult,12804,4));
// $Profile["unknown12808"] = asc2uint(substr($profileResult,12808,36));

// bandoliers[4]
	for ($x = 0; $x <= 3; $x++) {
		$Profile["bandoliers"][$x+1]["name"] = rtrim(substr($profileResult,$x*104+12844,32));
		for ($y = 0; $y <= 3; $y++) {
			$Profile["bandoliers"][$x+1]["items"][$y+1]["item_id"] = asc2uint(substr($profileResult,($x*104)+($y*72)+12876,4));
			$Profile["bandoliers"][$x+1]["items"][$y+1]["icon"] = asc2uint(substr($profileResult,($x*104)+($y*72)+12880,4));
			$Profile["bandoliers"][$x+1]["items"][$y+1]["item_name"] = rtrim(substr($profileResult,($x*104)+($y*72)+12884,64));
		};
	};

// $Profile["unknown14124"] = asc2uint(substr($profileResult,14124,5120));

// potionbelt[1] (should be 3 more somewhere)
	for ($x = 0; $x <= 3; $x++) {
		$Profile["potionbelt"][1]["items"][$x+1]["item_id"] = asc2uint(substr($profileResult,($x*72)+19244,4));
		$Profile["potionbelt"][1]["items"][$x+1]["icon"] = asc2uint(substr($profileResult,($x*72)+19248,4));
		$Profile["potionbelt"][1]["items"][$x+1]["item_name"] = rtrim(substr($profileResult,($x*72)+19252,64));
	};
	
// $Profile["unknown19532"] = asc2uint(substr($profileResult,19532,8));
$Profile["currentRadCrystals"] = asc2uint(substr($profileResult,19540,4));
$Profile["careerRadCrystals"] = asc2uint(substr($profileResult,19544,4));
$Profile["currentEbonCrystals"] = asc2uint(substr($profileResult,19548,4));
$Profile["careerEbonCrystals"] = asc2uint(substr($profileResult,19552,4));
$Profile["groupAutoconsent"] = asc2uint(substr($profileResult,19556,1));
$Profile["raidAutoconsent"] = asc2uint(substr($profileResult,19557,1));
$Profile["guildAutoconsent"] = asc2uint(substr($profileResult,19558,1));
// $Profile["unknown19559"] = asc2uint(substr($profileResult,19559,5));
	// Placeholder (cushion)
// $Profile["unknown15964"] = asc2uint(substr($profileResult,19564,4));

// Convert extprofile into array ExtProfile[]

$ExtProfile["pet_id"] = asc2uint(substr($extprofileResult,0,2));
$ExtProfile["pet_hp"] = asc2uint(substr($extprofileResult,2,2));
$ExtProfile["pet_mana"] = asc2uint(substr($extprofileResult,4,2));

// pet_buffs[25]

	for ($x = 0; $x <= 24; $x++) {
		$ExtProfile["pet_buffs"][$x+1]["slotid"] = asc2uint(substr($extprofileResult,$x*20+6,1));
		$ExtProfile["pet_buffs"][$x+1]["level"] = asc2uint(substr($extprofileResult,$x*20+7,1));
		$ExtProfile["pet_buffs"][$x+1]["bard_modifier"] = asc2uint(substr($extprofileResult,$x*20+8,1));
		$ExtProfile["pet_buffs"][$x+1]["effect"] = asc2uint(substr($extprofileResult,$x*20+9,1));
		$ExtProfile["pet_buffs"][$x+1]["spellid"] = asc2uint(substr($extprofileResult,$x*20+10,4));
		$ExtProfile["pet_buffs"][$x+1]["duration"] = asc2uint(substr($extprofileResult,$x*20+14,4));
		$ExtProfile["pet_buffs"][$x+1]["dmg_shield_remaining"] = asc2uint(substr($extprofileResult,$x*20+18,2));
		$ExtProfile["pet_buffs"][$x+1]["persistant_buff"] = asc2uint(substr($extprofileResult,$x*20+20,1));
		$ExtProfile["pet_buffs"][$x+1]["reserved"] = asc2uint(substr($extprofileResult,$x*20+21,1));
		$ExtProfile["pet_buffs"][$x+1]["player_id"] = asc2uint(substr($extprofileResult,$x*20+22,4));
	};



// pet_items[8]
	for ($x = 0; $x <= 7; $x++) {
		$ExtProfile["pet_items"][$x+1] = asc2uint(substr($extprofileResult,($x*4)+506,4));
	};

$ExtProfile["pet_name"] = rtrim(substr($extprofileResult,542,64));
$ExtProfile["aa_effects"] = asc2uint(substr($extprofileResult,606,4));
$ExtProfile["perAA"] = asc2uint(substr($extprofileResult,610,4));

?>